<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车列表</title>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="../js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
var currentPage=${currentPage }
var totalPage=${totalPage }
$(document).ready(function(){
	$(".page:eq(0)").click(function(){
		currentPage=1;
		getList();
	});
	$(".page:eq(1)").click(function(){
		if(currentPage==1){
			alert("已经是第一页")
		}else{
			currentPage--;
			getList();
		}
	});
	$(".page:eq(2)").click(function(){
		if(currentPage==totalPage){
			alert("已经是最后页")
		}else{
			currentPage++;
			getList();
		}
	});
	$(".page:eq(3)").click(function(){
		currentPage=totalPage;
		getList();
	});
	function getList(){
		var id=$(":hidden:first").val();
		location.href="GetShoppingcartListServlet?currentPage="+currentPage+"&id="+id;
	}

});

function del(id,goodsId,num){
	if(confirm("是否确定删除?")){
		location.href="DelShoppingcartServlet?id="+id+"&currentPage="+currentPage+"&num="+num+"&goodsId="+goodsId;
	}
}

function update(id,num){
	location.href="addshoppingcart.jsp?id="+id+"&currentPage="+currentPage+"&num="+num;
}

function clear1(){
	if(confirm("是否确定清空?")){
		location.href="ClearShoppingcartServlet";
	}
}	
	
function order(goodsId,num){
	if(confirm("是否确定下单?")){
		location.href="AddOrderServlet?goodsId="+goodsId+"&num="+num;
	}	
}
</script>
</head>
<body>
<a href="GetGoodsListServlet">商城主页</a>
<a href="GetShoppingcartListServlet">我的购物车</a>
<a href="GetOrderListServlet">我的订单</a>
<a href="personalinfo.jsp">个人信息</a>
<br>
<input type="button" value="请空购物车" onclick="clear1();">
<br>
<table border="1" width="80%">
	<tr>
	<th>商品名称</th><th>商品数量</th><th>商品总价</th><th>店铺名称</th><th>操作</th>
	</tr>
	<c:forEach items="${list }" var="b">
	<tr id="clear1">
		<td>${b.goods.goodsName}</td>
		<td>${b.goodsNum}</td>
		<td>${b.goods.goodsPrice*b.goodsNum}</td>
		<td>${b.goods.user.userShopname}</td>
		<td>
			<input type="button" value="删除" onclick="del(${b.shoppingcartId},${b.goods.goodsId},${b.goodsNum});">
			<input type="button" value="修改" onclick="update(
				${b.shoppingcartId},${b.goodsNum});">
			<input type="button" value="下单" onclick="order(${b.goods.goodsId},${b.goodsNum});">	
			<input type="hidden" value="${b.shoppingcartId}" name="id">
		</td>
	</tr>
	</c:forEach>
</table>
<input type="button" value="第一页" class="page">
<input type="button" value="上一页" class="page">
<input type="button" value="下一页" class="page">
<input type="button" value="最后页" class="page">
${currentPage }/${totalPage }
</body>
</html>